using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.Reflection;

namespace Common.Context
{
    public class Context
    {
        private Configuration configuration;
        private static Context instance = null;        

        public static Context GetInstance(Configuration config)
        {
            if (Context.instance == null)
            {
                Context.instance = new Context(config);                             
            }
            return Context.instance;
        }

        public static Context GetInstance()
        {
            if (Context.instance == null)
            {
                Configuration conf = null;
                Context.instance = new Context(conf);
            }
            return Context.instance;
        }

        private Context(Configuration config)
        {
            this.configuration = config;
        }        
        
        public string GetValueFromContext(string key)
        {
            try
            {
                if (this.configuration == null)
                {
                    return ConfigurationManager.AppSettings[key];
                }
                else
                {
                    return this.configuration.AppSettings.Settings[key].Value;             
                }
            }
            catch (Exception ex)
            {
                return String.Empty;
            }

        }
    }
}
